function FissureDamage takes nothing returns nothing
	local unit target = GetEnumUnit()
	//--
	if IsUnitEnemy(target , udg_TempPlayer) and IsUnitInRangeLoc(target , udg_TempLocation , udg_TempRadius) and GetUnitState(target , UNIT_STATE_LIFE) > 0.0 and not HaveSavedBoolean(udg_TempHashtable , GetHandleId(target) , 3)then
		call UnitDamageTarget(udg_TempDamager , target , udg_TempDamage , true , false , ATTACK_TYPE_NORMAL , DAMAGE_TYPE_COLD , WEAPON_TYPE_METAL_MEDIUM_BASH)
		call SaveBoolean(udg_TempHashtable , GetHandleId(target) , 3 , true)
	endif
	//--
	set target = null
endfunction

function FissureMove takes nothing returns nothing
	local unit fussure = GetEnumUnit()
	call SetUnitPosition(fussure , GetUnitX(fussure) + udg_TempDX + GetRandomReal(-5.0 , 5.0) , GetUnitY(fussure) + udg_TempDY + GetRandomReal(-5.0 , 5.0))
	set fussure = null
endfunction

function FissureRoutine takes nothing returns nothing
	local timer fissureTimer = GetExpiredTimer()
	local integer timerId = GetHandleId(fissureTimer)
	local location fissureLocation = LoadLocationHandle(udg_HT , timerId , 3)
	local real fissureX = GetLocationX(fissureLocation)
	local real fissureY = GetLocationY(fissureLocation)
	local real dx = LoadReal(udg_HT , timerId , 4)
	local real dy = LoadReal(udg_HT , timerId , 5)
	local real timeNow = LoadReal(udg_HT , timerId , 6)
	local real timeMax = LoadReal(udg_HT , timerId , 7 )
	local unit damager = LoadUnitHandle(udg_HT , timerId , 8)
	local player damagerOwner = GetOwningPlayer(damager)
	local unit fissureEffect = null
	local real timerInterval = LoadReal(udg_HT , timerId , 9)
	local group effects = LoadGroupHandle(udg_HT , timerId , 10)
	local integer damageCounter = LoadInteger(udg_HT , timerId , 11)
	local integer damageCounterMax = LoadInteger(udg_HT , timerId , 12)
	local integer crackCounter = LoadInteger(udg_HT , timerId , 13)
	local integer crackCounterMax = LoadInteger(udg_HT , timerId , 14)
	local hashtable damagedHashtable = LoadHashtableHandle(udg_HT , timerId , 15)
	//--
	if damageCounter >= damageCounterMax then
		call SaveInteger(udg_HT , timerId , 11 , 0)
		//造成傷害
		set udg_TempDamager = damager
		set udg_TempPlayer = damagerOwner
		set udg_TempDamage = 30.0
		set udg_TempRadius = 100.0
		set udg_TempLocation = fissureLocation
		set udg_TempHashtable = damagedHashtable
		set bj_wantDestroyGroup = true
		call ForGroupBJ(GetUnitsInRangeOfLocMatching(udg_TempRadius+70.0, udg_TempLocation , null) , function FissureDamage)
		set udg_TempDamager = null
		set udg_TempPlayer = null
		set udg_TempLocation = null
		set udg_TempHashtable = null
	else
		call SaveInteger(udg_HT , timerId , 11 , damageCounter + 1)
	endif
	
	if crackCounter >= crackCounterMax then
		call SaveInteger(udg_HT , timerId , 13 , 0)
		call CreateCrackTimed(fissureX , fissureY , "THND" , 2.0)
	else
		call SaveInteger(udg_HT , timerId , 13 , crackCounter + 1)
	endif
	
	//移動地裂點與特效
	if timeNow < timeMax then
		set timeNow = timeNow + timerInterval
		call SaveReal(udg_HT , timerId , 6 , timeNow)
		call MoveLocation(fissureLocation , fissureX + dx , fissureY + dy)
		set udg_TempDX = dx
		set udg_TempDY = dy
		call ForGroupBJ(effects , function FissureMove)
	else
		call PauseTimer(fissureTimer)
		call FlushChildHashtable(udg_HT , timerId)
		call DestroyGroup(effects)
		call RemoveLocation(fissureLocation)
		call FlushParentHashtable(damagedHashtable)
		call DestroyTimer(fissureTimer)
	endif
	//--
	set fissureTimer = null
	set fissureLocation = null
	set damager = null
	set damagerOwner = null
	set effects = null
	set damagedHashtable = null
endfunction

function Trig_Fissure_Actions takes nothing returns nothing
	local unit dino = GetTriggerUnit()
	local location dinoLocation = GetUnitLoc(dino)
	local location targetLocation = GetSpellTargetLoc()
	local real angle = AngleBetweenPoints(dinoLocation , targetLocation)
	local real radian = angle * bj_DEGTORAD
	local real speed = 1000.0
	local real timerInterval = 0.01
	local real timeMax = 1.0
	local integer damageCounterMax = 10
	local real effectOffset = 5.0
	local integer crackCounterMax = 33
	local real delta = speed * timerInterval
	local real dx = Cos(radian) * delta
	local real dy = Sin(radian) * delta
	local group effects = CreateGroup()
	local timer fissureTimer = CreateTimer()
	local integer timerId = GetHandleId(fissureTimer)
	local integer i = 0
	local unit fissureEffect = null
	local hashtable damagedHashtable = InitHashtable()
	//--
	call PlaySoundOnUnit(dino , "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.wav")
	call CreateCrackTimed(GetLocationX(dinoLocation) , GetLocationY(dinoLocation) , "THND" , 2.0)
	call SetUnitAnimationByIndex(dino , 1)
	call MoveLocation(targetLocation , GetLocationX(dinoLocation) , GetLocationY(dinoLocation))
	call SaveLocationHandle(udg_HT , timerId , 3 , targetLocation)
	loop
	exitwhen i >= 3
		set fissureEffect = CreateUnit(GetOwningPlayer(dino) , 'e00L' , GetLocationX(dinoLocation) + GetRandomReal(-effectOffset , effectOffset) , GetLocationY(dinoLocation) + GetRandomReal(-effectOffset , effectOffset) , GetRandomReal(0.0 , 360.0))
		call GroupAddUnit(effects , fissureEffect)
		call SetUnitAnimation(fissureEffect , "birth")
		call SetUnitScale(fissureEffect , GetRandomReal(0.5 , 0.8) , 1.0 , 1.0)
		call KillUnitinSecond(fissureEffect , 0.5)
	set i = i + 1
	endloop
	call SaveReal(udg_HT , timerId , 4 , dx)
	call SaveReal(udg_HT , timerId , 5 , dy)
	call SaveReal(udg_HT , timerId , 6 , 0.0) //timeNow
	call SaveReal(udg_HT , timerId , 7 , timeMax)
	call SaveUnitHandle(udg_HT , timerId , 8 , dino) //damager
	call SaveReal(udg_HT , timerId , 9 , timerInterval)
	call SaveGroupHandle(udg_HT , timerId , 10 , effects)
	call SaveInteger(udg_HT , timerId , 11 , 0)//damage counter
	call SaveInteger(udg_HT , timerId , 12 , damageCounterMax)//damage counter max
	call SaveInteger(udg_HT , timerId , 13 , 0)//crack counter
	call SaveInteger(udg_HT , timerId , 14 , crackCounterMax)//crack counter max
	call SaveHashtableHandle(udg_HT , timerId , 15 , damagedHashtable)
	call TimerStart(fissureTimer , timerInterval , true , function FissureRoutine)
	//--
	set dino = null
	call RemoveLocation(dinoLocation)
	set dinoLocation = null
	set targetLocation = null
	set fissureTimer = null
	set fissureEffect = null
	set damagedHashtable = null
endfunction

function Trig_Fissure_Conditions takes nothing returns boolean
	return GetSpellAbilityId() == 'A018'
endfunction

function InitTrig_Fissure takes nothing returns nothing
	set gg_trg_Fissure = CreateTrigger()
	call TriggerRegisterAnyUnitEventBJ(gg_trg_Fissure , EVENT_PLAYER_UNIT_SPELL_EFFECT)
	call TriggerAddCondition(gg_trg_Fissure , Condition(function Trig_Fissure_Conditions))
	call TriggerAddAction(gg_trg_Fissure , function Trig_Fissure_Actions)
endfunction